package restaurant;

import java.util.ArrayList;

import restaurant.iterators.Iterator;

/**
 * The Class cmdGetRatings.
 * 
 * @author Ebonie
 */

public class cmdGetRatings implements Command
{

	/** The info. */
	private InformationAggregator info;

	/** The item no. */
	private int itemNo;



	/**
	 * Instantiates a new cmd get ratings.
	 * 
	 * @param info the info
	 * @param itemNo the item no
	 */
	public cmdGetRatings(InformationAggregator info, int itemNo) {
		this.info = info;
		this.itemNo = itemNo;
	}



	/**
	 * Execute.
	 * 
	 * @return the item ratings.
	 * @see restaurant.Command#execute()
	 */
	@Override
	public Object execute()
	{
		CustomerComments comments = info.getComments();
		Iterator itemIterator = comments.getRatingsIterator(itemNo);
		ArrayList<Rating> ratings = new ArrayList<Rating>();
		Rating itemRating;

		while (itemIterator.hasNext()) {
			itemRating = (Rating) itemIterator.next();
			ratings.add(itemRating);
		}

		return ratings;
	}

}
